//+--------------------------------------------------------------------------------
//| Copyright (c) 2012 - 2013 ### an.vuongngocduy
//| This file is a part of Compact Game Engine (CGE)
//+--------------------------------------------------------------------------------
#ifndef __CGE_IMAGE_H__
#define __CGE_IMAGE_H__

#include "cgeCommons.h"
#include "cgeAllocator.h"
#include "cgeDimension2.h"
#include "cgeEnums.h"
#include "cgeColor.h"

using namespace cge::std;

namespace cge
{
	namespace gfx
	{
		//-- class prototype --//
		class ImageTranscoder;


		//! Simple implementation of image class to hold image data
		class Image
		{
		friend ImageTranscoder;

		public:
			struct Descriptor
			{
				u8* Data;
				Dimension2u Dimension;
				EPixelFormat Format;
			};

		public:
			//! Default constructor
			Image();


			//! Copy constructor
			Image(const Image& img);


			//! Construct new image form specified format and size
			Image(EPixelFormat format, const Dimension2u& size);


			//! Construct new image from buffer that have specified format and size
			Image(const u8* data, EPixelFormat format, const Dimension2u& dimension);


			//! Construct new image from buffer or use external memory directly
			Image(u8* data, EPixelFormat format,  const Dimension2u& dimension, b8 useExternalMem);


			//! Destructor
			~Image();


			//! Return pixel format
			EPixelFormat PixelFormat() const;


			//! Return bits per pixel
			u32 BitsPerPixel() const;


			//! Return size of image in byte
			u32 Size() const;


			//! Return image's dimension
			Dimension2u Dimension() const;


			//! Return image's width 
			u32 Width() const;


			//! Return image's height
			u32 Height() const;


			//! Return pointer to image's data
			const u8* Data() const;
			
			u8* Data();


			//! Get color of pixel at specified position
			Color GetPixel(u32 x, u32 y) const;

			
			//! Set color of pixel at specified position
			Image& SetPixel(const Color& col, u32 x, u32 y);

			
			//! Flip the image around X-axis
			Image& FlipVertical();

			
			//! Flip image around Y-axis
			Image& FlipHorizontal();

			
			//! Release resources used by image
			void Dispose();

			
			//! Copy content of specified image into current image
			Image& operator = (const Image& img);


		protected:
			Descriptor mDesc;
			Allocator<u8> mAlloc;
		};
	}
}

#endif//__CGE_IMAGE_H__